﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ASpect.Logic;

namespace ASpect
{
    public partial class EQForm : Form
    {
        bool eqon = false;
        private int[] _fxEQ = { 0, 0, 0, 0, 0 };

        public EQForm()
        {
            InitializeComponent();
        }

        public void EQFlat()
        {
            tb_eq1.Value = 3;
            tb_eq2.Value = 3;
            tb_eq3.Value = 3;
            tb_eq4.Value = 3;
            tb_eq5.Value = 3;
            UpdateEQ(0, 0);
            UpdateEQ(1, 0);
            UpdateEQ(2, 0);
            UpdateEQ(3, 0);
            UpdateEQ(4, 0);

        }

        public void UpdateEQ(int band, int gain)
        {
            if (eqon)
            {
                Un4seen.Bass.BASS_DX8_PARAMEQ eq = new Un4seen.Bass.BASS_DX8_PARAMEQ();
                if (Un4seen.Bass.Bass.BASS_FXGetParameters(_fxEQ[band], eq))
                {
                    eq.fGain = (float)(0 + gain * 5);
                    Un4seen.Bass.Bass.BASS_FXSetParameters(_fxEQ[band], eq);
                }
            }

        }
        public void CreateEQ(int stream)
        {
            Un4seen.Bass.BASS_DX8_PARAMEQ eq = new Un4seen.Bass.BASS_DX8_PARAMEQ();
            _fxEQ[0] = Un4seen.Bass.Bass.BASS_ChannelSetFX(stream, Un4seen.Bass.BASSFXType.BASS_FX_DX8_PARAMEQ, 0);
            _fxEQ[1] = Un4seen.Bass.Bass.BASS_ChannelSetFX(stream, Un4seen.Bass.BASSFXType.BASS_FX_DX8_PARAMEQ, 0);
            _fxEQ[2] = Un4seen.Bass.Bass.BASS_ChannelSetFX(stream, Un4seen.Bass.BASSFXType.BASS_FX_DX8_PARAMEQ, 0);
            _fxEQ[3] = Un4seen.Bass.Bass.BASS_ChannelSetFX(stream, Un4seen.Bass.BASSFXType.BASS_FX_DX8_PARAMEQ, 0);
            _fxEQ[4] = Un4seen.Bass.Bass.BASS_ChannelSetFX(stream, Un4seen.Bass.BASSFXType.BASS_FX_DX8_PARAMEQ, 0);
            eq.fBandwidth = 18f;
            eq.fGain = 0f;
            eq.fCenter = 100f;
            Un4seen.Bass.Bass.BASS_FXSetParameters(_fxEQ[0], eq);
            eq.fCenter = 2000f;
            Un4seen.Bass.Bass.BASS_FXSetParameters(_fxEQ[1], eq);
            eq.fCenter = 7000f;
            Un4seen.Bass.Bass.BASS_FXSetParameters(_fxEQ[2], eq);
            eq.fCenter = 10000f;
            Un4seen.Bass.Bass.BASS_FXSetParameters(_fxEQ[3], eq);
            eq.fCenter = 15000f;
            Un4seen.Bass.Bass.BASS_FXSetParameters(_fxEQ[4], eq);
            eqon = true;
        }

        private void tb_eq1_Scroll(object sender, EventArgs e)
        {
            UpdateEQ(0, tb_eq1.Value - 3);
        }

        private void tb_eq2_Scroll(object sender, EventArgs e)
        {
            UpdateEQ(0, tb_eq2.Value - 3);
        }

        private void tb_eq3_Scroll(object sender, EventArgs e)
        {
            UpdateEQ(0, tb_eq3.Value - 3);
        }

        private void tb_eq4_Scroll(object sender, EventArgs e)
        {
            UpdateEQ(0, tb_eq4.Value - 3);
        }

        private void tb_eq5_Scroll(object sender, EventArgs e)
        {
            UpdateEQ(0, tb_eq5.Value - 3);
        }
    }
}
